Programming Languages Section

Nim Programming Language

What is nim Programming Language
Post by Amina Delali, May 30th, 2023

Some Facts

The Nim programming language is a language that combines concepts from Python, Ada, and Modula. It is compiled, and statically typed. It generates native executables not dependant on a virtual machine. It supports all the major platforms, and it also compiles to different programming languages: C, C++, and JavaScript.

Nim can be used for System programming. And with the right libraries, it can also be used for web and game development.

It has been reported, that there are companies that already used Nim. Some of them are:CCP Games, Status.im, and Fivnex.



How to install it

  • on Windows:

    To install the Nim programming language you have to go to the Official Installation Page, and download the archive corresponding to your system. Now, you can follow these steps to start the installation:

    • extract the archive to a destination folder. For example, I extracted the archive I downloaded to D:\Downloads\nim-1.6.12_x64 folder
    • inside the archive, there is an executable file named finish.exe. Run the file (by double clicking on it). It will ask you if you want to install mingw, say y (for yes).
    • after the installation, find the file nim.cfg available in the config folder inside the extracted archive. For example, my file was in D:\Downloads\nim-1.6.12_x64\nim-1.6.12\config folder.
    • Open the nim.cfg file, and add the gcc.path value to reflect the path of the bin folder of the mingw just installed previously. The Mingw bin should be in the dist folder of the extracted archive. For example, for me the line became: gcc.path = r"D:\Downloads\nim-1.6.12_x64\nim-1.6.12\dist\mingw64\bin"
    • Now, edit the path environment variable to include the path of the nim bin folder. For example, I added this to the path variable D:\Downloads\nim-1.6.12_x64\nim-1.6.12\bin
      Now, you are all set, and you can start programming with Nim.
  • On Ubuntu
    • Before installing the Nim language on Ubuntu, you have to install the gcc compiler. To do this, just run the following commands sudo apt update
      sudo apt install gcc
    • Now, go again to the Unix installation Page, and run the following command to install choosenim, the Nim language Installer curl https://nim-lang.org/choosenim/init.sh -sSf | sh

    • After running the command, you will be prompted if you want nim to record and send anonymized telemetry data. You type y if you accept.

    • To check the installation, just run:

      nim --version
    • Now, you will have to edit the ~/.bashrc file to include the path of Nim. Run the command: nano ~./bashrc
    • Now, add the following line at the end of the file by replacing the username by your own username: export PATH=/home/username/.nimble/bin:$PATH
    • To enable the new path, run the following command: source ~/.bashrc

The Hello World Example

  • First of all, you are going to write your code in a file named hello.nim that you are going to save in your user folder.
  • Write the following code in the hello.nim file:
    echo "Hello World!"
  • To only compile the file, and generate a runnable, open the command prompt and run this command: nim compile hello.nim
  • Now, to run the generated file, run this command: hello.exe
  • To compile and run the code at the same time, run one of the two following commands:
    • nim compile --run hello.nim

    • nim c -r hello.nim


Something to say ?

If you want to add something about the Nim language or about this post, please feel free to do it by commenting below 🙂 .